package com.shine.sys.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shine.common.web.controller.BaseController;
import com.shine.common.web.model.DataTables;
import com.shine.common.web.validate.AjaxResponse;
import com.shine.sys.entity.Role;
import com.shine.sys.service.RoleService;

@Controller
@RequestMapping("/admin/sys/role")
public class RoleController extends BaseController {

	@Autowired
	private RoleService roleService ;
	
	@RequestMapping(value="/main", method=RequestMethod.GET)
	public String main(Model model) {
		return viewName("main") ;
	}
	
	@RequestMapping(value="/form", method=RequestMethod.GET)
	public String form(Integer id, Model model) {
		if(null != id) {
			model.addAttribute("id", id) ;
		}
		return viewName("form") ;
	}
	
	@RequestMapping(value="/add", method=RequestMethod.POST)
	@ResponseBody
	public AjaxResponse add(Role entity) {
		this.roleService.save(entity) ;
		return new AjaxResponse() ;
	}
	
	@RequestMapping(value="/delete", method=RequestMethod.POST)
	@ResponseBody
	public AjaxResponse delete(@RequestParam String ids) {
		this.roleService.deleteMoreforInt(ids);
		return new AjaxResponse() ;
	}
	
	@RequestMapping(value="/update", method=RequestMethod.POST)
	@ResponseBody
	public AjaxResponse update(Role entity) {
		this.roleService.update(entity) ;
		return new AjaxResponse() ;
	}
	
	@RequestMapping(value="/get/{id}", method=RequestMethod.GET)
	@ResponseBody
	public Role get(@PathVariable Integer id, Model model) {
		return this.roleService.get(id) ;
	}
	
	@RequestMapping(value="/datatables")
	@ResponseBody
	public DataTables datatables(Role entity) {
		return this.roleService.datatables(entity) ;
	}
	
	
	/**
	 * 分配资源UI
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/ui_resource/{id}", method=RequestMethod.GET)
	public String ui_resource(@PathVariable Integer id, Model model) {
		model.addAttribute("id", id) ;
		return viewName("ui_resource") ;
	}
	
	
	
	
	
}
